package com.sunsys.QuestionAnswer;

import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class QuestionsDAOImpl implements QuestionsDAO {
	DBConnection connection = new DBConnection();
	Connection con = connection.makeDBConnection();

	public List<QuestionDetails> getAnsweredQuestions() {
		List<QuestionDetails> list = new ArrayList<QuestionDetails>();
		
		try {
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select qname,qid from questions where isanswer=\"yes\"");
			while (rs.next()) {
				QuestionDetails questiondetails = new QuestionDetails();
				questiondetails.setQName(rs.getString(1));
				questiondetails.setQId(rs.getInt(2));
				list.add(questiondetails);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	public List<QuestionDetails> getUnAnsweredQuestions() {
		List<QuestionDetails> list = new ArrayList<QuestionDetails>();
		try {
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select qname,qid from questions where isanswer=\"no\"");
			QuestionDetails questiondetails = null;
			while (rs.next()) {
				questiondetails = new QuestionDetails();
				questiondetails.setQName(rs.getString(1));
				questiondetails.setQId(rs.getInt(2));
				list.add(questiondetails);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/*
	 * public List getRecentlyAnsweredQuestions() { Date date = new
	 * java.sql.Date(new java.util.Date().getTime()); date = date-10;
	 * 
	 * 
	 * }
	 */

}
